import re
import sys
import traceback
import urllib.error
import urllib.parse
import urllib.request

from proxy_generator import ProxyGenerator

class ProxyruGenerator(ProxyGenerator):
  def __init__(self):
    super().__init__()
    self.pages = ['http://proxy.com.ru/list_%d.html' % i for i in range(1, 8)]
    self._ip_port_pattern = re.compile(
        '<td>(\d*.\d*.\d*.\d*)</td>[^<]*<td>(\d+)</td>')
  
  def GetIps(self, webdata):
    webdata = webdata.decode('gbk')
    ip_ports = self._ip_port_pattern.findall(webdata)
    for pair in ip_ports:
      proxy = pair[0] + ':' + pair[1]
      yield proxy
